<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class BbsCategory extends Model
{
    use SoftDeletes;
    
    protected $table="bbs_category";
    
    protected $primaryKey = 'id';
    
    protected $fillable = ['id','title','type','icon','parent_id','sort','is_hot'];
    
    protected $dates = ['deleted_at'];
    
    /**
     * 根据子分类获取父分类
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function parentCate()
    {
        return $this->belongsTo('App\Models\BbsCategory', 'parent_id', 'id');
    }
    
    /**
     * 获取某个父分类下的所有子分类
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function childrenCates()
    {
        return $this->hasMany('App\Models\BbsCategory', 'parent_id', 'id');
    }
}
